<?php
/**
 * 坐标相关
 * User: functions
 * Date: 2016/6/14
 * Time: 19:54
 */

namespace Tools\Map;


class Map
{
    /*
     * 地球半径
     */
    const EARTH_RADIUS = 6371000;

    /**
     * 计算球面亮点距离
     * @param $latitude1
     * @param $longitude1
     * @param $latitude2
     * @param $longitude2
     * @return float
     */
    public static function getDistance($latitude1, $longitude1, $latitude2, $longitude2)
    {
        $dLat = deg2rad($latitude2 - $latitude1);
        $dLon = deg2rad($longitude2 - $longitude1);

        $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon / 2) * sin($dLon / 2);
        $c = 2 * asin(sqrt($a));
        $d = static::EARTH_RADIUS * $c;
        return round($d);
    }
}